$(function(){
    $('.search .button_02').click(function () {
        var phone = $(".search .input_01").val();
        if (phone==''){
            alert("请输入手机号");
            return;
        }
        if (!checkPhone(phone)){
            alert("手机号码有误，请重填");
            return false;
        }


        var timer,count = 60,
            that = $(this);


        var $btn = $(this);



        $(this).attr("disabled", true);

        $.ajax({
            url: "/infoLogin/snedInfo.html",
            data: {'phone':phone},
            type: "POST",
            dataType: "json",
            success: function (res) {
                /*
                 * @weisf
                 * 手机格式不正确
                 */
                if(res.code !=1){
                    alert(res.msg);
                    $btn.text('获取验证码');
                    return;
                }
            },
            error: function () {
                $btn.text('获取失败');
            }
        });
        /* 倒计时 */
        /*延迟一秒问题*/
        setTimeout(function(){
            that.html(count +　'(s)');
        },0);
        /*一分钟后再次发送*/
        timer = setInterval(function(){
            if(count > 1){
                count --;
                // alert($(this).html())
                that.html(count +　'(s)');
            }else{
                counting = false;
                count = 60;
                that.html("获取验证码");

                clearInterval(timer);
                $('.search .button_02').attr("disabled", false);
            }

        },1000)


    });


    $(".search .login").click(function () {
        var phone = $(".search .input_01").val();
        if (phone==''){
            alert("请输入手机号");
            return;
        }
        if (!checkPhone(phone)){
            alert("手机号码有误，请重填");
            return false;
        }
        var coode = $('.search .input_02').val();
        if (coode==''){
            alert("请输入验证码");
            return;
        }
        if (!(/^\d{6}$/.test(coode))) {
            alert("请输入正确验证码");
            return false;
        }

        var postdata = {phone:phone,code:coode};

        var load = new Loading();
        load.init();

        $.ajax({
            url: "/order/selectInfo.html",
            data: postdata,
            type: "POST",
            dataType: "json",
            beforeSend: function () {

                load.start();
            },//执行ajax前执行loading函数.直到success
            success: function (data){
                console.log(data);
                if( data.code!=1 ){
                    alert(data.msg);
                    load.stop();
                    return;
                }
                load.stop();
                var queryType=$("#queryType").val();
                if(queryType==1){
                    window.location.href='/order/refundOrderList.html?phone='+phone;
                    return;
                }
                window.location.href='/order/orderList.html?phone='+phone;
            },
            error: function (data) {

                console.log(data);

                alert("错误！！！");
            }
        })


    })
})